package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;
    @GetMapping("/findAll")
    public List<User> findAll(){
        return userService.findAll();
    }
    @PostMapping("/login")
    public SysResult login(@RequestBody User user){
        String token=userService.login(user);
        if (!StringUtils.hasLength(token)){
            return SysResult.fail();
        }
        return SysResult.success(token);
    }
}
